//	Description
/*	CodeEval::Moderate Sudoku
	
	Sudoku is a number-based logic puzzle. It typically comprises of a 9*9 grid 
	with digits so that each column, each row and each of the nine 3*3 sub-grids 
	that compose the grid contains all the digits from 1 to 9. For this challenge, 
	you will be given an N*N grid populated with numbers from 1 through N and you 
	have to determine if it is a valid sudoku solution. You may assume that N will 
	be either 4 or 9. The grid can be divided into square regions of equal size, 
	where the size of a region is equal to the square root of a side of the entire 
	grid. Thus for a 9*9 grid there would be 9 regions of size 3*3 each.

	Input Sample:

		4;1,4,2,3,2,3,1,4,4,2,3,1,3,1,4,2
		4;2,1,3,2,3,2,1,4,1,4,2,3,2,3,4,1

	Output Sample:

		True
		False

 */

//	Pseudocode
/*	Solution by Michael Pio Arroyo (mpio)
 
	Get first number in line and store for reference
	Traverse line to extract each number
	Tally up occurences of each number
	If each number has a tally equal to first number 
	Then return true otherwise return false

	WHILE not at end of file	
		bool N is false
		vector of 4 integers
		vector of 9 integers
		FOR duration of current line

			IF N is not found THEN
				IF iterator is not semicolon THEN
					Add character to string
				ELSE			
					Convert string to integer and store to N
					Clear string
					N found
				ENDIF
			ELSE
				IF iterator is not comma THEN
					Add character to string
				ELSE
					Convert string to integer for x
					Clear string
					Increment array of size N at x
				ENDIF
			ENDIF

		ENDFOR

		Valid is true

		FOR all elements in array

			IF array value at index does not equal index plus one THEN
				Valid is false
			ENDIF

		ENDFOR

	Print Valid

	ENDWHILE

 */

#include <iostream>
#include <fstream>
#include <string>

int main(int argc, char** argv) {
	std::ifstream file;
	std::string line;
	std::string itget;
	std::string::iterator it;
	file.open(argv[1]);

	//// Print input
	//while (std::getline(file, line)) {
	//	std::cout << line << "\n";
	//}
	//std::cout << std::endl;
	//file.close();
	//file.open("test.txt");

	//	bool N is false
	bool Nfound = false;
	int N = 0;
	int x = 0;
	//	array of 4 integers
	int sudoku4[4];
	//	array of 9 integers
	int sudoku9[9];

	//	WHILE not at end of file
	while (getline(file, line)) {
		for (int i = 0; i < 4; ++i)
			sudoku4[i] = 0;
		for (int i = 0; i < 9; ++i)
			sudoku9[i] = 0;
		
		//	FOR duration of current line
		for (it = line.begin(); it != line.end(); ++it) {
			//	IF N is not found THEN
			if (!Nfound) {
				//	IF iterator is not semicolon THEN
				if (*it != ';') {
					//	Add character to string
					itget = *it;
				}
				else {
					//	Convert string to integer and store to N
					N = std::stoi(itget);
					//	Clear string
					itget.clear();
					//	N found
					Nfound = true;
				}
				//	ENDIF
			}
			else {
				//	IF iterator is not comma THEN
				if (*it != ',') {
					//	Add character to string
					itget = *it;
				}	//	ELSE
				else {
					//	Convert string to integer for x
					x = std::stoi(itget);
					//	Clear string
					itget.clear();
					//	Increment array of size N at x
					if (N == 4)
						++sudoku4[x-1];
					else
						++sudoku9[x-1];
				}
				//	ENDIF
			}
			//	ENDIF
		}
		x = std::stoi(itget);
		itget.clear();
		if (N == 4)
			++sudoku4[x-1];
		else
			++sudoku9[x-1];
		//	ENDFOR

		//	Valid is true
		bool Valid = true;

		if (N == 4) {
			//	FOR all elements in array
			for (int i = 0; i < N; ++i) {
				//	IF array value at index does not equal index plus one THEN
				if (sudoku4[i] != N) {
					//	Valid is false
					Valid = false;
					//	ENDIF
				}
				//	ENDFOR
			}
		}
		else {
			//	FOR all elements in array
			for (int i = 0; i < N; ++i) {
				//	IF array value at index does not equal index plus one THEN
				if (sudoku9[i] != N) {
					//	Valid is false
					Valid = false;
					//	ENDIF
				}
				//	ENDFOR
			}
		}
		if (Valid)
			std::cout << "True" << std::endl;		
		else
			std::cout << "False" << std::endl;
			
		//	bool N is false
		Nfound = false;
		N = 0;
		x = 0;
	}
	
	file.close();
	return 0;
}